<template>
    <view>
        <cu-custom bgColor="bg-gradual-green" :isBack="true">
            <block slot="content">课程详情</block>
            <block slot="backText">返回</block>
        </cu-custom>
        <view>
            <uni-list v-if="showChapterOn">
                <pop-item :notif="getOnInfo()" @itempressed = "checkClass"></pop-item>
            </uni-list>
        </view>
        <view>
            <chapterID :chapters="chapters" @haschapteron="checkChapterOn"></chapterID>
        </view>
    </view>
</template>

<script>
import chapterID from './chapterID.vue';
import popItem from './popItem.vue';
import uniList from '@/components/third_party/uni-list/uni-list.vue';

export default {
    components: {
        chapterID,
        popItem,
        uniList
    },
    data() {
        return {
            showChapter: false,
            chapters: [],
            course_id: 1024,
            showChapterOn: false,
            onChapter: undefined,
            course_title: ''
        };
    },
    onLoad(e) {
        var paraStr = JSON.parse(e.chapters);
        this.chapters = paraStr.chapters;
        this.sortChapters();
        this.course_id = paraStr.course_id;
        this.course_title = paraStr.course_title;
    },
    onReady() {
        this.$nextTick(() => {
            this.showChapter = true;
        });
    },
    methods: {
        closePop(e) {
            if(e.show === false)
                this.showChapterOn = false;
        },
        checkChapterOn(e) {
            if(e.state === true) {
                this.onChapter = e;
                this.showChapterOn = true;
            }
        },
        getOnInfo() {
            return this.onChapter.chapter_title;
        },
        sortChapters() {
            this.chapters.sort(function(a, b) {
                var lessThan = a.course_date < b.course_date || a.course_date === b.course_date && a.start_time < b.start_time;
                return lessThan ? -1 : 1;
            });
        },
        checkClass() {
            uni.navigateTo({
                url: '../courseOn/courseOn',
                success: function() {
                    //console.log('navigate to pic success');
                },
                fail: function() {
                    //console.log('navigate to pic fail');
                }
            });
        }
    }
};
</script>

<style lang="scss" scoped>
    /* #ifndef APP-NVUE */
    page {
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        background-color: #efeff4;
        min-height: 100%;
        height: auto;
    }
	/* #endif */
</style>
